#2683: Make _util.Final support static analysis by converting to a decorator.#2793
Merged
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2793 +/- ##
=======================================
Coverage 98.97% 98.97%
=======================================
Files 115 115
Lines 17053 17102 +49
Branches 3044 3079 +35
=======================================
+ Hits 16878 16927 +49
Misses 121 121
Partials 54 54
|
jakkdl
approved these changes
Sep 7, 2023
A5rocks
reviewed
Sep 8, 2023
A5rocks
left a comment
Contributor
There was a problem hiding this comment.
Mostly minor comments. RE: making a new PR, just rebasing so you have like 3 commits to show specifically which commit is adding new final classes would work too.
As a bonus this lets us avoid a special case for enums, which are automatically final if they have members.
A5rocks
approved these changes
Sep 9, 2023
A5rocks
left a comment
Contributor
There was a problem hiding this comment.
Any remaining threads from my past review are just opinions on implementation: choose what you want! I think anything sounds good and this PR looks good.
Contributor
|
Not sure if you want this squashed and merged or if you want to rebase to have several commits! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#2683: By converting
_util.Finalto be a decorator instead of a metaclass, we can alias it with thetyping.finaldecorator. This will make type checkers also refuse to allow subclasses, and allow them to do type narrowing in some cases. Unfortunately I can't see a way to do the same withNoPublicConstructor, so instead I added a test which verifies all uses of that are also@final.Aside from the static typing benefits, this simplifies the implementation a little and allows
_util.finalto be used on any class since we don't have metaclass conflicts.There's a lot of changes here, since I modified every place
FinalorNoPublicConstructoris used. The actual important changes are intrio/_util.pyandtrio/_tests/test_util.py. Theverify_types_*.jsontables drop 2 private symbols because of the removal of_util.Final.